package com.signway.module_signway_adapter_Api;

import android.content.Context;
import android.util.Log;

import com.signway.module_signway_adapter_Api.constant.ScreenResolutionBean;
import com.signway.open.api.IOpenDisplayApi;
import com.signway.opensdk.interfaces.base.Callback1;
import com.signway.opensdk.internal.command.signway.ApiConst;
import com.signway.opensdk.model.SDKResult;
import com.signway.opensdk.sdk.SDK;
import com.signway.utils.LogHelper;

/*
 * -----------------------------------------------------------------
 * Copyright (C) 2011-2019, by your Signway, All rights reserved.
 * -----------------------------------------------------------------
 *
 * ProjectName: droid5119
 *
 * Author: Administrator
 *
 * Email: pf.wang@Signway.cn
 *
 * Description:
 *
 * -----------------------------------------------------------------
 * 2019-5-29 : Create SignwayDisplayApi.java
 * -----------------------------------------------------------------
 */
public class SignwayDisplayApi implements IOpenDisplayApi {
    private static final String TAG = "SignwayDisplayApi";
    private static SignwayDisplayApi mSignwayDisplayApi;
    private static Context mContext;

    public static synchronized SignwayDisplayApi getInstance(Context context) {
        mContext = context;
        if (mSignwayDisplayApi == null) {
            mSignwayDisplayApi = new SignwayDisplayApi(context);
        }
        return mSignwayDisplayApi;
    }

    public SignwayDisplayApi(Context context) {
        this.mContext = context;
    }

    public void setBackLightEnable(boolean isEnabled) {
    }

    public void setBrightness(int value) {
        SDK.displayApi().setScreenBrightness(0,value, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("setBrightness msg:" + booleanSDKResult.getContent());
            }
        });
    }
    public void setBrightness(int id ,int value) {
        LogHelper.d("setBrightness id:" + id + "  value:" + value);
        SDK.displayApi().setScreenBrightness(id, value, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("setBrightness msg:" + booleanSDKResult.getContent());
            }
        });
    }

    public int getBrightness(int id) {
        final int[] s = new int[1];
        int brightnessValue = 0;
        Log.d(TAG, "getBrightness id:" + id);
        SDK.displayApi().getScreenBrightness(id, new Callback1<SDKResult<Integer>>() {
            @Override
            public void onMsg(SDKResult<Integer> integerSDKResult) {
                s[0] = integerSDKResult.getContent();
                Log.d(TAG, "getBrightness callback：" + s[0]);
            }
        });
        Log.d(TAG, "getBrightness：" + s[0]);

        brightnessValue = s[0];
        return brightnessValue;
    }

    //对比度
    public void setContrast(int value) {

    }

    public void setColor(int value) {
    }

    public void setTint(int value) {
    }

    public void setSharpness(int value) {
    }

    @Override
    public String getLvdsResolution(int value) {
        final String[] s = new String[1];
        int lvdsResolution = 0;
        Log.d(TAG, "获得屏幕分辨率");
        SDK.displayApi().getScreenResolution(ApiConst.ScreenID.SCREEN_ID_LVDS, new Callback1<SDKResult<String>>() {
            @Override
            public void onMsg(SDKResult<String> stringSDKResult) {
                s[0] = stringSDKResult.getContent();
            }
        });
        Log.d(TAG, "得到屏幕分辨率结果：" + s[0]);

        if(s[0] != null && s[0].contains("@")){
            ScreenResolutionBean screenResolutionBean = new ScreenResolutionBean();
            lvdsResolution = screenResolutionBean.screenResolution(s[0]);
        }


        return lvdsResolution + "";
    }

    @Override
    public void setLvdsResolution(int value) {

    }

    @Override
    public void setBacklightInverse(int screen, int status) {
        boolean isStatus = true;
        if (status == 0) {
            isStatus = false;
        }
        Log.d(TAG, "setBacklightInverse screen：" + screen + "  status:" + status + "isStatus:" + isStatus);
        SDK.displayApi().setScreenBacklightInverse(screen, isStatus, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> integerSDKResult) {
                Log.d(TAG, "setBacklightInverse result：" + integerSDKResult.getContent());
            }
        });
    }

    @Override
    public int getScreenBacklightInverse(int id) {
        final int[] backInverse = new int[1];
        SDK.displayApi().getScreenBacklightInverse(id, new Callback1<SDKResult<Integer>>() {
            @Override
            public void onMsg(SDKResult<Integer> integerSDKResult) {
                backInverse[0] = integerSDKResult.getContent();
            }
        });
        return backInverse[0];
    }

    @Override
    public void setBacklightMode(int screen, int mode) {
        SDK.displayApi().setScreenBacklightMode(screen, mode, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                Log.d(TAG, "setBacklightMode result：" + booleanSDKResult.getContent());
            }
        });
    }

    @Override
    public int getScreenBacklightMode(int id) {
        final int[] lightMode = new int[1];
        SDK.displayApi().getScreenBacklightMode(id, new Callback1<SDKResult<Integer>>() {
            @Override
            public void onMsg(SDKResult<Integer> integerSDKResult) {
                lightMode[0] = integerSDKResult.getContent();
            }
        });
        return lightMode[0];
    }

    @Override
    public void setScreenBrightness(int id, int brightness) {
        SDK.displayApi().setScreenBrightness(id, brightness, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                Log.d(TAG, "setScreenBrightness result：" + booleanSDKResult.getContent());
            }
        });
    }

    @Override
    public int getScreenBrightness(int id) {
        final int[] backlight = new int[1];
        SDK.displayApi().getScreenBrightness(id, new Callback1<SDKResult<Integer>>() {
            @Override
            public void onMsg(SDKResult<Integer> integerSDKResult) {
                backlight[0] = integerSDKResult.getContent();
            }
        });
        return backlight[0];
    }

    @Override
    public boolean setScreenOnoff(int id, boolean onoff) {
        final boolean[] result = new boolean[1];
        SDK.displayApi().setScreenOnoff(id, onoff, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("setScreenOnoff lvds callback ===" + booleanSDKResult.getValid() + "  " + booleanSDKResult.getContent());
                result[0] = booleanSDKResult.getContent();
            }
        });
        return result[0];
    }

    @Override
    public boolean getScreenStatus(int id) {
        return false;
    }

    @Override
    public boolean setScreenResolution(int id, String resolution) {
        return false;
    }

    @Override
    public String getScreenResolution(int id) {
        return null;
    }

    @Override
    public boolean setHdmiOnoff(boolean onoff) {
        final boolean[] result = new boolean[1];
        SDK.displayApi().setHdmiOnoff(onoff, new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("setScreenOnoff hdmi callback ===" + booleanSDKResult.getValid() + "  " + booleanSDKResult.getContent());
                result[0] = booleanSDKResult.getContent();
            }
        });
        return result[0];
    }

    @Override
    public boolean getHdmiOnoff() {
        final boolean[] result = new boolean[1];
        SDK.displayApi().getHdmiOnoff(new Callback1<SDKResult<Boolean>>() {
            @Override
            public void onMsg(SDKResult<Boolean> booleanSDKResult) {
                LogHelper.d("setScreenOnoff hdmi callback ===" + booleanSDKResult.getValid() + "  " + booleanSDKResult.getContent());
                result[0] = booleanSDKResult.getContent();
            }
        });
        return result[0];
    }

    @Override
    public boolean setHdmiResolution(int resolution) {
        return false;
    }

    @Override
    public String getHdmiResolution() {
        return null;
    }

    @Override
    public boolean setLvdsMode(String id, int mode) {
        return false;
    }

    @Override
    public int getLvdsMode(String id) {
        return 0;
    }

    @Override
    public boolean setLvdsSwap(String id, int swap) {
        return false;
    }

    @Override
    public int getLvdsSwap(String id) {
        return 0;
    }

    @Override
    public boolean setLvdsChannel(int screen, int channel) {
        return false;
    }

    @Override
    public int getLvdsChannel(int screen) {
        return 0;
    }


}
